package com.cn.java8.study;

import org.junit.jupiter.api.Test;

import java.util.*;

/**
 * @Description TODO
 * @Author 作者： cm
 * @DATE 创建时间： 2021/8/25 16:23
 * @Version 版本：1.0
 */
public class java8Lambada {

    @Test
    public void example(){
        List<String> names1 = new ArrayList<String>();
        names1.add("Google ");
        names1.add("Runoob ");
        names1.add("Taobao ");
        names1.add("Baidu ");
        names1.add("Sina ");

        List<String> names2 = new ArrayList<String>();
        names2.add("Google ");
        names2.add("Runoob ");
        names2.add("Taobao ");
        names2.add("Baidu ");
        names2.add("Sina ");

        java8Lambada tester = new java8Lambada();
        System.out.println("使用 Java 7 语法: ");
        tester.sortUsingJava7(names1);
        System.out.println(names1);

        System.out.println("使用 Java 8 语法: ");
        tester.sortUsingJava8(names2);
        System.out.println(names2);
    }

    // 使用 java 7 排序
    private void sortUsingJava7(List<String> names){
      Collections.sort(names, new Comparator<String>() {
          @Override
          public int compare(String o1, String o2) {
              return 0;
          }
      });
    }

    // 使用 java 8 排序
    private void sortUsingJava8(List<String> names){
        Collections.sort(names, (s1, s2) -> s1.compareTo(s2));
    }

    @Test
    public void test1(){
        List<String> names1 = new ArrayList<String>();
        names1.add("1212");
        names1.add("31231 ");
        names1.add("2323 ");
        names1.add("12322 ");
        names1.add("12312321");
        names1.stream().filter(name->Integer.parseInt(name.trim())>1).limit(2).forEach(System.out::println);
        Collections.sort(names1, (s1, s2) -> s1.compareTo(s2));
        Comparator<Integer> comparator = (x,y)->x.compareTo(y);
        TreeSet treeSet = new TreeSet<>(comparator);
    }

    @Test
    public void test2(){
    }
}
